***** Setting up graphical scheme *****
** grstyle+palette package for gray scale
	grstyle clear
	grstyle init
	grstyle set imesh, horizontal compact 	
	grstyle set legend 6, nobox
	grstyle set color 538, n(4)
	grstyle set symbol
	grstyle set lpattern

/* Packages Note - You will need the following Stata packages for graphical
   code to work:
   (1) grc1leg2 
   (2) coefplot
*/   



********************************************************************************
********************* Figure 2 *************************************************
********************************************************************************
import delimited "usa_main.csv", varnames(1) clear  

quietly ologit concede i.intervene, robust
	margins r.intervene, post 
	estimates store usa1
quietly ologit repress i.intervene, robust
	margins r.intervene, post 
	estimates store usa2

import delimited "can_main.csv", varnames(1) clear

quietly ologit concede i.intervene, robust
	margins r.intervene, post 
	estimates store can1
quietly ologit repress i.intervene, robust
	margins r.intervene, post 
	estimates store can2
	
coefplot usa1 can1, bylabel("(a) Concede") ///
	vertical ciopts(recast(rcap)) ///
	xlabel(1 `""Strongly" "Disagree""' 2 `""Somewhat" "Disagree""' ///
		   3 "Neither" ///
		   4 `""Somewhat" "Agree""' 5 `""Strongly" "Agree""') ///
	xtitle("Predicted Respondent Outcome", height(5)) ///
	mlabel mlabcol(black) format(%10.2g) mlabpos(2) color(*.75) /// 
	ytitle("") ///
	title("(a) Concede") rescale(100) ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	legend(order(2 "USA" 4 "Canada")) ///
	name(figure1a, replace)
	
coefplot usa2 can2, bylabel("(b) Repress") ///
	vertical ciopts(recast(rcap)) ///
	xlabel(1 `""Strongly" "Disagree""' 2 `""Somewhat" "Disagree""' ///
		   3 "Neither" ///
		   4 `""Somewhat" "Agree""' 5 `""Strongly" "Agree""') ///
	title("(b) Repress") rescale(100) ///
	xtitle("Predicted Respondent Outcome", height(5)) ///
	mlabel mlabcol(black) format(%10.2g) mlabpos(2) color(*.75) /// 
	ytitle("") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	 legend(order(2 "USA" 4 "Canada")) ///
	name(figure1b, replace)
	
** Graph Combine	
graph combine figure1a figure1b, ycommon xcommon rows(1) xsize(6) ysize(3.5) ///
	  	l1title("Average Marginal Treatment" "Effect of Foreign Interference (%)", size(small)) ///
		scale(1.3)
	  	
		
********************************************************************************
***** Figure 3	****************************************************************
********************************************************************************


*********** Outgroups and Country Identity 

import delimited "usa_main.csv", varnames(1) clear 
quietly ologit concede i.intervene##i.outsider, robust 
	quietly margins r.intervene, at(outsider=0) post
	estimates store usaout1
quietly ologit concede i.intervene##i.outsider, robust 
	quietly margins r.intervene, at(outsider=1) post
	estimates store usaout2	
quietly ologit repress i.intervene##i.outsider, robust 
	quietly margins r.intervene, at(outsider=0) post
	estimates store usaout3
quietly ologit repress i.intervene##i.outsider, robust 
	quietly margins r.intervene, at(outsider=1) post
	estimates store usaout4
	
import delimited "can_main.csv", varnames(1) clear 
quietly ologit concede i.intervene##i.outsider, robust 
	quietly margins r.intervene, at(outsider=0) post
	estimates store canout1
quietly ologit concede i.intervene##i.outsider, robust 
	quietly margins r.intervene, at(outsider=1) post
	estimates store canout2	
quietly ologit repress i.intervene##i.outsider, robust 
	quietly margins r.intervene, at(outsider=0) post
	estimates store canout3
quietly ologit repress i.intervene##i.outsider, robust 
	quietly margins r.intervene, at(outsider=1) post
	estimates store canout4
	
*** concession figure	
coefplot usaout1 canout1, vertical ciopts(recast(rcap)) ///
		 xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
			    5 `""5" "Strongly" "Agree""') ///
		 xtitle("Concede to Protesters", height(5)) /// 
		 ytitle("") title("(a) In-group") ///
		 yline(0, lpattern(dash) lcolor(black*.5)) ///
		 legend(off) ///
		 name(out_concede1, replace)

coefplot usaout2 canout2, vertical ciopts(recast(rcap)) ///
		 xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
			    5 `""5" "Strongly" "Agree""') ///		 xtitle("Concede to Protesters", height(5)) /// 
		 ytitle("") title("(b) Out-group") ///
		 yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
		 name(out_concede2, replace)

*** repression figure 
coefplot usaout3 canout3, vertical ciopts(recast(rcap)) ///
		 xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
			    5 `""5" "Strongly" "Agree""') ///
		 xtitle("Repress Protesters", height(5)) ///
		 ytitle("") title("(c) In-group") ///
		 yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
		 name(out_repress1, replace)

coefplot usaout4 canout4, vertical ciopts(recast(rcap)) ///
		 xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
			    5 `""5" "Strongly" "Agree""') ///
		 xtitle("Repress Protesters", height(5)) ///
		 ytitle("") title("(d) Out-group") ///
		 yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
		 name(out_repress2, replace)


graph combine out_concede1 out_concede2 out_repress1 out_repress2, ///
	  ycommon xcommon rows(2) ///
	  name(outgroup, replace) title("In-group/Out-group", size(medium)) 
	  

*** Type of Support*************************************************************

import delimited "usa_main.csv", varnames(1) clear

** Concede
quietly ologit concede i.support, robust 
	quietly margins r.support if support==0 | support==1, post
	estimates store usasup1
quietly ologit concede i.support, robust 
	quietly margins r.support if support==0 | support==2, post
	estimates store usasup2
** Repress
quietly ologit repress i.support, robust 
	quietly margins r.support if support==0 | support==1, post
	estimates store usasup3
quietly ologit repress i.support, robust 
	quietly margins r.support if support==0 | support==2, post
	estimates store usasup4
	

import delimited "can_main.csv", varnames(1) clear 
** Concede
quietly ologit concede i.support, robust 
	quietly margins r.support if support==0 | support==1, post
	estimates store cansup1
quietly ologit concede i.support, robust 
	quietly margins r.support if support==0 | support==2, post
	estimates store cansup2
** Repress
quietly ologit repress i.support, robust 
	quietly margins r.support if support==0 | support==1, post
	estimates store cansup3
quietly ologit repress i.support, robust 
	quietly margins r.support if support==0 | support==2, post
	estimates store cansup4

	
coefplot usasup1 cansup1, vertical ciopts(recast(rcap)) ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
	xtitle("Concede to Protesters", height(5)) ///
	ytitle("") ///
	title("(e) Financial") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	legend(off) ///
	name(sup1, replace)

coefplot usasup2 cansup2, vertical ciopts(recast(rcap)) ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
	xtitle("Concede to Protesters", height(5)) ///
	ytitle("") ///
	title("(f) Training") ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	name(sup2, replace)
	
coefplot usasup3 cansup3, vertical ciopts(recast(rcap)) ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
	xtitle("Repress Protesters", height(5)) ///
	ytitle("") ///
	title("(g) Financial") ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	name(sup3, replace)
	
coefplot usasup4 cansup4, vertical ciopts(recast(rcap)) ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
	xtitle("Repress Protesters", height(5)) ///
	ytitle("") ///
	title("(h) Training") ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	name(sup4, replace)

** Graph Combine	
graph combine sup1 sup2 sup3 sup4, ///
	  ycommon xcommon rows(2) name(support, replace) ///
	  title("Type of Foreign Interference", size(medium)) 
	  

***** Timing *******************************************************************
	  
import delimited "usa_main.csv", varnames(1) clear
** Concede
quietly ologit concede i.timing, robust 
	quietly margins r.timing if timing==0 | timing==1, post
	estimates store usatime1
quietly ologit concede i.timing, robust 
	quietly margins r.timing if timing==0 | timing==2, post
	estimates store usatime2
** Repress
quietly ologit repress i.timing, robust 
	quietly margins r.timing if timing==0 | timing==1, post
	estimates store usatime3
quietly ologit repress i.timing, robust 
	quietly margins r.timing if timing==0 | timing==2, post
	estimates store usatime4
	

import delimited "can_main.csv", varnames(1) clear 
** Concede
quietly ologit concede i.timing, robust 
	quietly margins r.timing if timing==0 | timing==1, post
	estimates store cantime1
quietly ologit concede i.timing, robust 
	quietly margins r.timing if timing==0 | timing==2, post
	estimates store cantime2
** Repress
quietly ologit repress i.timing, robust 
	quietly margins r.timing if timing==0 | timing==1, post
	estimates store cantime3
quietly ologit repress i.timing, robust 
	quietly margins r.timing if timing==0 | timing==2, post
	estimates store cantime4

	
coefplot usatime1 cantime1, vertical ciopts(recast(rcap)) ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
	xtitle("Concede to Protesters", height(5)) ///
	ytitle("") ///
	title("(i) Before") ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	legend(off) ///
	name(time1, replace)

coefplot usatime2 cantime2, vertical ciopts(recast(rcap)) ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
	xtitle("Concede to Protesters", height(5)) ///
	ytitle("") ///
	title("(j) After") ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///	
	name(time2, replace)
	
coefplot usatime3 cantime3, vertical ciopts(recast(rcap)) ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
	xtitle("Repress Protesters", height(5)) ///
	ytitle("") ///
	title("(k) Before") ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///	
	name(time3, replace)	
	
coefplot usatime4 cantime4, vertical ciopts(recast(rcap)) ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" 3 "3" 4 "4" ///
		   5 `""5" "Strongly" "Agree""') ///
	xtitle("Repress Protesters", height(5)) ///
	ytitle("") ///
	title("(l) After") ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///	
	name(time4, replace)

** Graph Combine	
graph combine time1 time2 time3 time4, ///
			  ycommon xcommon rows(2) ///
			  title("Timing of Interference", size(medium)) ///
			  name(tim, replace)
		
		

graph combine outgroup support tim, rows(1) xsize(6.5) ysize(3) scale(1.4) ///
	  l1("Average Marginal Treatment Effect of Foreign Interference", size(small))
		

********************************************************************************
***** Figure 6 Heterogeneous Marginal Treatment Effects (Repression) ***********
********************************************************************************

**** Environmentalism
import delimited "usa_main.csv", varnames(1) clear
** Calculate percentile values
_pctile environment, p(20)
	return list				/* -0.791 */
_pctile environment, p(40)
	return list 			/* -0.136 */
_pctile environment, p(60)
	return list				/* 0.398 */
_pctile environment, p(80)
	return list				/* 1.034 */



quietly ologit repress i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=-.791) post
	estimates store usa1
quietly ologit repress i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=-.136) post
	estimates store usa2				
quietly ologit repress i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=.399) post
	estimates store usa3
quietly ologit repress i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=1.034) post
	estimates store usa4	
	
import delimited "can_main.csv", varnames(1) clear 
** Calculate percentile values
_pctile environment, p(20)
	return list				/* -0.893 */
_pctile environment, p(40)
	return list 			/* -0.09 */
_pctile environment, p(60)
	return list				/* 0.471 */
_pctile environment, p(80)
	return list				/* 0.91 */

quietly ologit repress i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=-.893) post
	estimates store can1
quietly ologit repress i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=-.09) post
	estimates store can2		
quietly ologit repress i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=.471) post
	estimates store can3
quietly ologit repress i.intervene##c.environment, robust
	quietly margins r.intervene, at(environment=.91) post
	estimates store can4			
			
coefplot usa1 can1, ///
	vertical ciopts(recast(rcap)) ///
	title("(a) Environmentalism" "20th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	legend(off) ///
	mlabel format(%9.0f) mlabcol(black) mlabpos(1) rescale(100) ///
	name(env1, replace)

coefplot usa2 can2, ///
	vertical ciopts(recast(rcap)) ///
	title("(b) Environmentalism" "40th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) rescale(100) ///
	legend(off) ///
	name(env2, replace)

coefplot usa3 can3, ///
	vertical ciopts(recast(rcap)) ///
	title("(c) Environmentalism" "60th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) rescale(100) ///
	legend(off) ///
	name(env3, replace)


coefplot usa4 can4, ///
	vertical ciopts(recast(rcap)) ///
	title("(d) Environmentalism" "80th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) ///
	legend(off) ///
	mlabel format(%9.0f) mlabcol(black) mlabpos(1) rescale(100) ///
	name(env4, replace)

** Graph Combine	
graph combine env1 env2 env3 env4, ///
		 xcommon ycommon rows(1) ///
		 name(environmentalism, replace) ///
		 b1title("Predicted Respondent Outcome (Repress)", size(small)) ///
		 l1title("Average Marginal Treatment" ///
				 "Effect of Foreign Interference", size(small))
		 

	
**** Nationalism
import delimited "usa_main.csv", varnames(1) clear
** Calculate percentile values
_pctile nationalism, p(20)
	return list				/* -0.823 */
_pctile nationalism, p(40)
	return list 			/* -0.132 */
_pctile nationalism, p(60)
	return list				/* 0.523 */
_pctile nationalism, p(80)
	return list				/* 0.869 */

quietly ologit repress i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=-.823) post
	estimates store usa1
quietly ologit repress i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=-.132) post
	estimates store usa2				
quietly ologit repress i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=.523) post
	estimates store usa3
quietly ologit repress i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=0.869) post
	estimates store usa4	
	
import delimited "can_main.csv", varnames(1) clear 
** Calculate percentile values
_pctile nationalism, p(20)
	return list				/* -0.552 */
_pctile nationalism, p(40)
	return list 			/* -0.085 */
_pctile nationalism, p(60)
	return list				/* 0.564 */
_pctile nationalism, p(80)
	return list				/* 0.849 */
	
quietly ologit repress i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=-.552) post
	estimates store can1
quietly ologit repress i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=-.085) post
	estimates store can2		
quietly ologit repress i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=.564) post
	estimates store can3
quietly ologit repress i.intervene##c.nationalism, robust
	quietly margins r.intervene, at(nationalism=.849) post
	estimates store can4			
			
coefplot usa1 can1, ///
	vertical ciopts(recast(rcap)) ///
	title("(e) Nationalism" "20th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	mlabel format(%9.0f) mlabcol(black) mlabpos(1) rescale(100) ///
	name(nat1, replace) 

coefplot usa2 can2, ///
	vertical ciopts(recast(rcap)) ///
	title("(f) Nationalism" "40th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') rescale(100)  ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	name(nat2, replace) 

coefplot usa3 can3, ///
	vertical ciopts(recast(rcap)) ///
	title("(g) Nationalism" "60th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') rescale(100) ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	name(nat3, replace) 


coefplot usa4 can4, ///
	vertical ciopts(recast(rcap)) ///
	title("(h) Nationalism" "80th Percentile") ///
	xlabel(1 `""1" "Strongly" "Disagree""' 2 "2" ///
		   3 "3" 4 "4" 5 `""5" "Strongly" "Agree""') ///
	yline(0, lpattern(dash) lcolor(black*.5)) legend(off) ///
	mlabel format(%9.0f) mlabcol(black) mlabpos(1) rescale(100) ///
	name(nat4, replace) 


** Graph Combine	
graph combine nat1 nat2 nat3 nat4, ///
		 xcommon rows(1) ycommon ///
		 name(nationalism, replace) ///
		 b1title("Predicted Respondent Outcome (Repress)", size(small)) ///
		 l1title("Average Marginal Treatment" ///
				 "Effect of Foreign Interference", size(small)) 
		 
graph combine environmentalism nationalism, rows(2) ///
	  xsize(7) ysize(5) scale(1.3)
		   
	
